<!--<?php
    session_start();
    if($_SESSION['uid']==""||$_SESSION['level']!=3){
		header("Location: ./exit.php");
		exit();
	}
	
?>-->
<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="Bookmark" href="/favicon.ico" >
<link rel="Shortcut Icon" href="/favicon.ico" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<!--/meta 作为公共模版分离出去-->

<title>公寓管理</title>
</head>
<body>
		<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 公寓管理 <span class="c-gray en">&gt;</span> 新增公寓 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<article class="page-container">
	<div class="cl pd-5 mybg-2 bk-gray">
			<span class="r">
				<button onclick="removeIframe()" class="btn btn-primary radius">关闭选项卡</button>
				 <!--<a href="javascript:;" onclick="datadel()" class="btn btn-danger radius">
				 <i class="Hui-iconfont">&#xe6e2;</i> 批量删除
				 </a>
				 <a class="btn btn-primary radius" data-title="添加公寓" data-href="apartment-add.html" onclick="Hui_admin_tab(this)" href="javascript:;">
					 <i class="Hui-iconfont">&#xe600;</i> 添加公寓
				 </a>-->
			</span>
	</div>
	<div class="form form-horizontal mybg-2" id="form-article-add">
		<!--<div class="row cl pt-10">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>公寓编号：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="只允许数字" id="id" name="id">
				<label id="id-error" class="error valid" for="id" style="display:none;">这是必填字段</label>
			</div>
		</div>-->
		<div class="row cl pt-10">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>公寓名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="不超过二十个字" id="name" name="name">
				<label id="name-error" class="error valid" for="name" style="display:none;">这是必填字段</label>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">公寓简称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="不超过十个字" id="abbreviation" name="abbreviation">
				<label id="abbreviation-error" class="error valid" for="abbreviation" style="display:none;">超出字数限制</label>
			</div>
		</div>
		<div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>公寓分类：</label>
            <div class="formControls col-xs-8 col-sm-9">
				<select id="property" class="select" size="1" style="height:29px;">
					<option value="1" selected="">女生宿舍楼</option>
                    <option value="2">男生宿舍楼</option>
                    <option value="3">混合宿舍楼</option>
				</select>
            </div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>楼层数：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="只允许数字" id="height" name="height">
				<label id="height-error" class="error valid" for="height" style="display:none;">这是必填字段</label>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>每层房间数：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="只允许数字" id="rooms" name="rooms">
				<label id="rooms-error" class="error valid" for="rooms" style="display:none;">这是必填字段</label>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>每个房间床位数：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="只允许数字" id="beds" name="beds">
				<label id="beds-error" class="error valid" for="beds" style="display:none;">这是必填字段</label>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">备注：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea id="remarks" name="remarks" cols="" rows="" class="textarea"  placeholder="备注..." datatype="*10-100" dragonfly="true" onKeyUp="$.Huitextarealength(this,200)"></textarea>
				<p class="textarea-numberbar"><em class="textarea-length">最多30字</p>
				<label id="remarks-error" class="error valid" for="remarks" style="display:none;">超出字数限制</label>
			</div>
		</div>

		<div class="row cl pb-5">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
				<button id="submit" class="btn btn-primary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 下一步</button>
				<button onClick="removeIframe();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
			</div>
		</div>
	</div>
	
</article>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer /作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript">

$(function(){
	//恢复默认样式
	$("input").click(function(){
		$(this).removeClass('error');
		var val=$(this).attr("id");
		var label_id="#"+val+"-error";
		$(label_id).hide();
	});

	//提交
	$("#submit").click(function(){
		//creatIframe("apartment_edit.html?id=1","详细信息设置");
		//min_titleList();
		//window.location.href="apartment_edit.html?id=1";
		//location.replace();
		//validate()

		//window.location.href=jsonObject.url;
		//location.replace();
		//提交时检查
		if(validate()){
			$.post("./php/apartment-add.php",
			{
				id:$("#id").val(),
				name:$("#name").val(),
				abbreviation:$("#abbreviation").val(),
				property:$("#property").val(),
				height:$("#height").val(),
				rooms:$("#rooms").val(),
				beds:$("#beds").val(),
				remarks:$("#remarks").val()
			},
			function(jsonString){
				var jsonObject=JSON.parse(jsonString);
				//alert(jsonString);
				switch(parseInt(jsonObject.code)){
					case 2001:
						$.Huimodalalert(jsonObject.message,1000);
						setTimeout(function(){
							creatIframe(jsonObject.url,"详细信息设置");
							min_titleList();
							//window.location.href=jsonObject.url;
							//location.replace();
							},1000);
						break;
					case 2002:
						$.Huimodalalert("提交失败",1000);
						validate_server(jsonObject.message,1);
						break;
					case 2003:
						$.Huimodalalert("提交失败",1000);
						validate_server(jsonObject.message,2);
						break;
					case 2004:
						$.Huimodalalert("提交失败",1000);
						break;
					default:
						$.Huimodalalert("提交失败",1000);
						break;
				}

			});
		}
	});
	//当点击输入框时
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});

	//表单验证
	function validate(){
		var id_array=new Array("#id","#name","#height",
		"#rooms","#beds",);
		var error_array=new Array("#id-error","#name-error",
		"#height-error","#rooms-error","#beds-error");
		var flag=true;
		for(var i=0;i<id_array.length;i++){
			if($(id_array[i]).val()==""){
				$(id_array[i]).addClass('error');
				$(error_array[i]).show();
				flag=false;
			}
		}
		var abbreviation_str="";
		abbreviation_str=$("#abbreviation").val();
		if(abbreviation_str.length>10)
		{
			$("#abbreviation").addClass('error');
			$("#abbreviation-error").show();
			flag=false;
		}
		var remarks_str="";
		remarks_str=$("#remarks").val();
		if(remarks_str.length>30){
			$("#remarks").addClass('error');
			$("#remarks-error").show();
			flag=false;
		}

		return flag;
	}
	//显示服务端验证信息
	function validate_server(message,code){
		var array=Array("编号","名称");
		var id_array=new Array("#id","#name","#abbreviation","#height",
			"#rooms","#beds","#remarks");
		var error_array=new Array("#id-error","#name-error","#abbreviation-error",
			"#height-error","#rooms-error","#beds-error","#remarks-error");
		switch(code){
			case 1:
				$.each(message, function(e, value) {
					//alert(id_array[value]);
					$(id_array[value]).addClass('error');
					$(error_array[value]).show();
					$(error_array[value]).html("输入不符合要求");
				});
			break;
			case 2:
				$.each(message, function(e, value) {
					//alert(id_array[value]);
					$(id_array[value]).addClass('error');
					$(error_array[value]).show();
					$(error_array[value]).html(array[value]+"已存在");
				});
			break;
			default:break;
		}
		//alert(message);
		
		return;
	}
	
});
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>